package br.com.lazyprogrammer.social.infestit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import br.com.lazyprogrammer.social.infestit.R;
import br.com.lazyprogrammer.social.infestit.model.MenuItem;

/**
 * Created by Andre on 10/09/2014.
 */
public class MenuAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<MenuItem> items = new ArrayList<MenuItem>();

    public MenuAdapter(Context context) {
        inflater = LayoutInflater.from(context);

        String[] names = context.getResources().getStringArray(R.array.menu);
        items.add(new MenuItem(names[0], context.getResources().getDrawable(R.drawable.ic_launcher)));
        items.add(new MenuItem(names[1], context.getResources().getDrawable(R.drawable.ic_launcher)));
        items.add(new MenuItem(names[2], context.getResources().getDrawable(R.drawable.ic_launcher)));
        items.add(new MenuItem(names[3], context.getResources().getDrawable(R.drawable.ic_launcher)));
        //items.add(new MenuItem(names[4], context.getResources().getDrawable(R.drawable.tab_config_normal)));
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public MenuItem getItem(int i) {
        return items.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.item_menu, viewGroup, false);
            holder.viewIcon = (ImageView) view.findViewById(R.id.menu_icon);
            holder.viewName = (TextView) view.findViewById(R.id.menu_name);
            view.setTag(holder);
        }
        else
            holder = (ViewHolder) view.getTag();

        MenuItem item = getItem(i);
        holder.viewName.setText(item.getName());
        holder.viewIcon.setImageDrawable(item.getIcon());

        return view;
    }

    class ViewHolder {
        ImageView viewIcon;
        TextView viewName;
    }
}
